package cn.doitedu.day03

//ReduceLeft和ReduceRight是有区别的
object ReduceRightDemo {

  def main(args: Array[String]): Unit = {

    val arr = Array(1,2,3,4,5,6)

    val r1 = arr.reduceLeft(_ + _)
    println(r1)

    val r2 = arr.reduceRight(_ + _)
    println(r2)

    //如果reduceLeft和reduceRight传入的函数都是相减，有没有区别
    val r3 = arr.reduceLeft(_ - _)
    println(r3)

    //1 - (2 - (3 - (4 - (5 - 6))))
    //5 - 6 = -1
    //4 - (-1) = 5
    //3 - 5 = -2
    //2 - (-2) = 4
    //1 - 4 = -3
    val r4 = arr.reduceRight(_ - _)
    println(r4)



  }

}
